package com.wiiss.common.utils;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * @author my
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class UriUtils {

    private String protocol = "http";

    private String ip;

    private Integer port;

    public URI getUri() {
        try {
            return new URI("http://" + this.ip + ":" + this.port);
        } catch (URISyntaxException e) {
            log.error("创建URI异常IP:[{}],PORT:[{}]", this.ip, this.port);
            log.error("创建URI异常", e);
        }
        return null;
    }

    public static URI getUri(String url) {
        try {
            return new URI(url);
        } catch (URISyntaxException e) {
            log.error("getUri", e);
        }
        return null;
    }
}
